package com.cloudkinto.appletController.fbaorderoutput;


import com.cloudkinto.appletservice.fbaorderoutput.AppletFbaOrderOutputService;
import com.cloudkinto.base.BaseController;
import com.cloudkinto.common.annotations.UserSessionRequired;
import com.cloudkinto.common.web.PageResult;
import com.cloudkinto.common.web.SingleResult;
import com.cloudkinto.service.fbaorderoutput.FbaOrderOutputService;
import com.cloudkinto.service.fbaorderoutput.vo.FbaOrderOutputUpdateTimeReq;
import com.cloudkinto.service.orderoutput.vo.*;
import com.cloudkinto.service.stock.StockRecordService;
import com.cloudkinto.service.stock.vo.record.StockRecordPageRes;
import io.swagger.annotations.*;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.Map;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author 张永远
 * @since 2020-06-04
 */
@RestController
@Api(tags = "小程序fba转运模块")
@RequestMapping("/api/applet/fbaOrderOutput")
public class AppletFbaOrderOutputController extends BaseController {
    private final Logger logger = LoggerFactory.getLogger(AppletFbaOrderOutputController.class);

    @Autowired
    private AppletFbaOrderOutputService service;


    @UserSessionRequired
    @GetMapping("/{id}")
    @ApiOperation(value = "根据id查看详情", notes = "根据id查看详情")
    @ApiResponses({@ApiResponse(code = 200, message = "", response = OrderOutputDetailRes.class)})
    public SingleResult detail(@PathVariable("id") Long id) {
        return SingleResult.success("查询成功", service.detail(id));
    }


    @UserSessionRequired
    @GetMapping("/listPage")
    @ApiOperation(value = "查询（分页）", notes = "查询（分页）")
    @ApiImplicitParams({@ApiImplicitParam(name = "keyword", value = "关键字搜索"), @ApiImplicitParam(name = "keyword", value = "关键字搜索"),
            @ApiImplicitParam(name = "current", value = "当前页"), @ApiImplicitParam(name = "pagesize", value = "页大小"),
            @ApiImplicitParam(name = "status", value = "订单状态"),
            @ApiImplicitParam(name = "trackId", value = "快递公司"), @ApiImplicitParam(name = "storageId", value = "仓库id"),
            @ApiImplicitParam(name = "shopId", value = "店铺id"), @ApiImplicitParam(name = "storageId", value = "仓库id")
            , @ApiImplicitParam(name = "startDate", value = "开始时间"), @ApiImplicitParam(name = "endDate", value = "结束时间")})
    @ApiResponses({@ApiResponse(code = 200, message = "", response = OrderOutputListRes.class)})
    public PageResult<OrderOutputListRes> listPage(String keyword, String current, String pageSize,
                                                   String status, String startDate, String endDate, String trackId, String shopId, String storageId) {
        Long companyId = getCompanyId();
        Map<String, String> map = new HashMap<>();
        map.put("keyword", keyword);
        map.put("current", current);
        map.put("pageSize", pageSize);
        map.put("status", status);
        map.put("startDate", startDate);
        map.put("endDate", endDate);
        map.put("trackId", trackId);
        map.put("storageId", storageId);
        map.put("orderType", "2");//fba转运
        if (!StringUtils.isEmpty(shopId)) {
            map.put("shopId", shopId);
        } else if (getShopId() != null) {
            map.put("shopId", getShopId() + "");
        }
        map.put("companyId", companyId + "");
        return service.getListPage(map);
    }

}

